﻿import QtQuick 2.0
import "../../js/UI.js" as Style
import "../common"

Rectangle {
    id: messageBoxBackground
    property string m_prompt:""
    property int fontSize : 0.03 * parent.height
    property bool m_result: true
    signal itemClicked(int index)
    signal closeSignal(bool m_res)

    property bool staus: false;

    onVisibleChanged: if(visible===false)staus = false;

    function doModal(prompt)
    {
        m_prompt = prompt;
        messageBoxBackground.state = "visible";
        Qt.inputMethod.hide();
    }

    function hide() {
        messageBoxBackground.state = "";
        m_result = true;
    }

    function getVisbleState() {
        return (messageBoxBackground.state == "visible")
    }

    visible: false
    anchors.fill: parent
    color: "#20000000"
    //点击对话框区域外，隐藏对话框，其父窗口最后变为最外层窗口，在Component.onCompleted事件中设置
    MouseArea {
        anchors.fill: parent//
        onClicked:
        {

        }
    }

    // 对话框
    BaseDialog{
        Rectangle {
            id: messageBox
            color: "white"
            width: m_root_id.width - (Style.LeftScale + Style.RightScale) * 4 * m_lineValue
            height: 3.6 * m_lineValue + 4
            radius: m_lineValue*0.2
            //        anchors.horizontalCenter: parent.horizontalCenter
            //        anchors.verticalCenter: parent.verticalCenter
            anchors.centerIn: parent;
            Rectangle
            {
                width: parent.width*0.8
                height: parent.height*0.68
                anchors.left: parent.left
                anchors.leftMargin: 0.1*parent.width
                AText
                {
                    id:textText
                    //                width: parent.width
                    //                height:0.55 * parent.height
                    horizontalAlignment:Text.AlignHCenter
                    verticalAlignment:Text.AlignVCenter
                    width: parent.width*0.9
                    // height: paintedHeight>m_lineValue*0.6?paintedHeight+m_lineValue*0.4:m_lineValue
                    font.pointSize: Style.fontContentSize
                    wrapMode:Text.WordWrap
                    text:m_prompt
                    //color: Style.TitletextColor
                    anchors.centerIn: parent
                    //anchors.horizontalCenter: parent.horizontalCenter
                    lineHeight: 1.2
                }
            }

            //            SplitLine{
            //               // width: parent.width-m_lineValue*0.4
            //                anchors.horizontalCenter: parent.horizontalCenter
            //            }
            RadiusBotton{
                id:sureTr
                width: parent.width*0.5
                height:0.32 * parent.height
                anchors.bottom: parent.bottom
                anchors.left: parent.left
                m_text: "确定"
                btnEnable: false
                onCanvasClicked:{
                    messageBoxBackground.state = "";
                    closeSignal(true)
                }
            }
            RadiusBotton{
                width: parent.width*0.5
                height:0.32 * parent.height
                anchors.bottom: parent.bottom
                anchors.right: parent.right
                m_text: "取消"
                btnEnable: true
                onCanvasClicked:{
                    messageBoxBackground.state = "";
                    closeSignal(false)
                }
            }
            SplitLine{
                width: parent.width
                anchors.top: sureTr.top
                anchors.left: parent.left
            }
            Vertical_Line{
                height: sureTr.height
                anchors.horizontalCenter: parent.horizontalCenter
                anchors.bottom: parent.bottom
            }

            //            Row
            //            {
            //                width: parent.width
            //                height:m_lineValue
            //                Rectangle{
            //                    width: (parent.width-1)/2
            //                    height: parent.height
            //                    AText
            //                    {
            //                        anchors.fill: parent
            //                        horizontalAlignment:Text.AlignHCenter
            //                        verticalAlignment:Text.AlignVCenter
            //                        font.pointSize: Style.fontContentSize
            //                        text: staus?"否":"取消"
            //                        color: Style.titlePontColor
            //                    }
            //                    MouseArea {
            //                        id: mouseid
            //                        anchors.fill: parent//
            //                        onClicked:
            //                        {
            //                            messageBoxBackground.state = "";
            //                            closeSignal(false)
            //                        }
            //                    }
            //                    color: mouseid.pressed?Style.mousePressedColor:"transparent"
            //                }
            //                Rectangle{
            //                    width: 1
            //                    height: parent.height
            //                    color: Style.sprlitLineColor
            //                }
            //                Rectangle{
            //                    width: (parent.width-1)/2
            //                    height: parent.height
            //                    AText
            //                    {
            //                        anchors.fill: parent
            //                        horizontalAlignment:Text.AlignHCenter
            //                        verticalAlignment:Text.AlignVCenter
            //                        font.pointSize: Style.fontContentSize
            //                        text: staus?"是":"确定"
            //                        color: Style.titlePontColor
            //                    }
            //                    MouseArea {
            //                        id: rightbtn
            //                        anchors.fill: parent//
            //                        onClicked:
            //                        {
            //                            messageBoxBackground.state = "";
            //                            closeSignal(true)
            //                        }
            //                    }
            //                    color: rightbtn.pressed?Style.mousePressedColor:"transparent"
            //                }
            //            }

        }
    }
    states: State {
        name: "visible"
        PropertyChanges {target: messageBoxBackground; visible: true}
    }
    transitions: Transition {
        NumberAnimation {
            target:  messageBoxBackground
            properties: "visible"
            duration: 250
        }
    }
    Component.onCompleted:
    {
        //        var docRoot = messageBoxBackground.parent;
        //        while(docRoot.parent)
        //        {
        //            docRoot = docRoot.parent;
        //        }
        //        messageBoxBackground.parent = docRoot;
    }
}

